
var homeInfo=null;
var userId;
var Performanceitem = {
    init:function(){
        userId = getQueryString("userid");
        this.getData(1,1,userId);
    },
    eventLisenter:function(){
        var that = this;
        $(".intenthtml").click(function(){
            window.location.href=$(this).attr("href");
        });
        $(".basehtml").scroll(function(e){
            var scrollHeight=$(".basehtml")[0].scrollHeight;
            var height = $(window).height();
            var scrollTop= $(".basehtml").scrollTop();

            if(homeInfo&&homeInfo.hasNext){
                if(scrollTop == scrollHeight-height){
                    that.getData(1,homeInfo.pageNo++);
                    // $("#home .p").text("正在加载");
                }
            }else if(homeInfo&&!homeInfo.hasNext){
                $("#home .p").text("-没有更多-");
            }
        });
    },
    getData:function(type,pageNo,userid){
        // $(".p").text("正在加载");
        new AjaxRequest({
            type: "post",
            url:apiService.mySpreadOrderList+"?type="+type+"&userid="+userid,
            param: JSON.stringify({pageNo:pageNo,limit:10}),
            callBack:function(res){
                $(".dataCount").text(res.payload.dataCount);
                $(".awardAmt").text(res.payload.awardAmt);
                $(".nickName").text(res.payload.nickName);

                var data = res.payload.items;
                homeInfo = res.pageInfo;
                changelock("#home",homeInfo);
                for (let i = 0; i < data.length; i++) {
                    buildDom(data[i],"#home");
                }
            },
            failBack: function(){
                $(".p").text("-没有更多了-");
            }
        });
    }
}

//正则获取url参数
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}
function changelock(id,data){
    if(data&&data.hasNext){
        $(id+" .p").text("加载更多");
    }else if(data&&!data.hasNext){
        $(id+" .p").text("-没有更多-");
    }
}

function oncilk(dom){
    window.location.href=$(dom).attr("href");
}
function buildDom(data,id){
    var dom1 = `<div class="textinfo flexs-pace-between">
                    <div class="la" style="width:45%">
                        <span>用户昵称</span>
                        <span>${data.nickname}</span>
                        <!--<a href="performanceitem.html?uesrid=${data.userId}">查看全部</a>-->
                    </div>
                    <div class="la" style="width:55%">
                        <p>支付时间：${data.dateStr}</p>
                    </div>
                </div>
                <div class="jl-item flexs-pace-between" style="margin-top:0">
                    <div class="flexs-center jl-l">
                        <img src=""/>
                        <div style="margin-left:0.5rem">
                            <p>${data.goodsTitle}</p>
                            <p>用户性质 : ${data.userType}</p>
                            <p>赠送数量 : ${data.quantity}</p>
                        </div>
                    </div>
                    <div class="flexs-center jl-r">
                        <p style="color:#6b6b6b;">+${data.awardAmt}元</p>
                    </div>
                </div>`;
    var dom = `<div class="textinfo flexs-pace-between">
                    <div class="la" style="width:45%">
                        <span>用户昵称</span>
                        <span>${data.nickname}</span>
                        <!--<a href="performanceitem.html?uesrid=${data.userId}">查看全部</a>-->
                    </div>
                    <div class="la" style="width:55%">
                        <p>支付时间：${data.dateStr}</p>
                    </div>
                </div>
                <div class="jl-item flexs-pace-between" style="margin-top:0">
                    <div class="flexs-center jl-l">
                        <img src="${data.goodsImg}"/>
                        <div style="margin-left:0.5rem">
                            <p>${data.goodsTitle}</p>
                            <p>数量 : ${data.quantity}</p>
                            <p>金额 : ${data.orderAmt}</p>
                        </div>
                    </div>
                    <div class="flexs-center jl-r">
                        <p style="color:#6b6b6b;">+${data.awardAmt}元</p>
                    </div>
                </div>`;
    if(data.itemType==1){
        $(id+" .c").append(dom1);
    }else if(data.itemType==2){
        $(id+" .c").append(dom2);
    }

}